# *-* coding: utf-8 *-*
from __future__ import absolute_import

from PyQt4.QtGui import QIcon
from PyQt4.QtCore import SIGNAL
from PyQt4.QtCore import QObject

from ninja_ide import resources
from ninja_ide.core import settings
from ninja_ide.gui import actions


class MenuSource(QObject):

    def __init__(self, menuSource):
        QObject.__init__(self)

        showHideFindErrors = menuSource.addAction(
            QIcon(resources.IMAGES['bug']),
            self.tr("Show/&Hide Find Errors in this File"))
        showHideCheckStyle = menuSource.addAction(
            self.tr("Sho&w/Hide Check Style Errors in this File"))
        menuSource.addSeparator()
        indentMoreAction = menuSource.addAction(
            QIcon(resources.IMAGES['indent-more']),
            self.tr("Indent More (Tab)"))
        indentLessAction = menuSource.addAction(
            QIcon(resources.IMAGES['indent-less']),
            self.tr("Indent Less (Shift+Tab)"))
        menuSource.addSeparator()
        commentAction = menuSource.addAction(
            QIcon(resources.IMAGES['comment-code']),
            self.tr("Comment ($1+D)", settings.OS_KEY))
        unCommentAction = menuSource.addAction(
            QIcon(resources.IMAGES['uncomment-code']),
            self.tr("Uncomment ($1+D)", settings.OS_KEY))
        horizontalLineAction = menuSource.addAction(
            self.tr("Insert Horizontal Line ($1+R)", settings.OS_KEY))
        titleCommentAction = menuSource.addAction(
            self.tr("Insert Title Comment ($1+T)", settings.OS_KEY))
        countCodeLinesAction = menuSource.addAction(
            self.tr("Count Code Lines"))
        menuSource.addSeparator()
        goToDefinitionAction = menuSource.addAction(
            self.tr("Go To Definition ($1+Enter or $1+Click)", settings.OS_KEY))
        insertImport = menuSource.addAction(self.tr("Insert &Import ($1+U)",
            settings.OS_KEY))
        organizeImportsAction = menuSource.addAction(
            self.tr("&Organize Imports"))
        removeUnusedImportsAction = menuSource.addAction(
            self.tr("Remove Unused &Imports"))
        extractMethodAction = menuSource.addAction(
            self.tr("Extract selected &code as Method"))
        menuSource.addSeparator()
        removeTrailingSpaces = menuSource.addAction(
            self.tr("&Remove Trailing Spaces"))
        replaceTabsSpaces = menuSource.addAction(
            self.tr("Replace Tabs With &Spaces"))
        moveUp = menuSource.addAction(self.tr("Move &Up"))
        moveDown = menuSource.addAction(self.tr("Move &Down"))
        duplicate = menuSource.addAction(self.tr("Duplica&te"))

        self.connect(goToDefinitionAction, SIGNAL("triggered()"),
            actions.Actions()._editor_go_to_definition)
        self.connect(countCodeLinesAction, SIGNAL("triggered()"),
            actions.Actions().count_file_code_lines)
        self.connect(insertImport, SIGNAL("triggered()"),
            actions.Actions().import_from_everywhere)
        self.connect(indentMoreAction, SIGNAL("triggered()"),
            actions.Actions()._editor_indent_more)
        self.connect(indentLessAction, SIGNAL("triggered()"),
            actions.Actions()._editor_indent_less)
        self.connect(commentAction, SIGNAL("triggered()"),
            actions.Actions()._editor_comment)
        self.connect(unCommentAction, SIGNAL("triggered()"),
            actions.Actions()._editor_comment)
        self.connect(horizontalLineAction, SIGNAL("triggered()"),
            actions.Actions()._editor_insert_horizontal_line)
        self.connect(titleCommentAction, SIGNAL("triggered()"),
            actions.Actions()._editor_insert_title_comment)
#        QObject.connect(removeUnusedImportsAction, SIGNAL("triggered()"), lambda: self._main._central.obtain_editor().remove_unused_imports())
##        QObject.connect(addMissingImportsAction, SIGNAL("triggered()"), lambda: self._main._central.obtain_editor().add_missing_imports())
#        QObject.connect(organizeImportsAction, SIGNAL("triggered()"), lambda: self._main._central.obtain_editor().organize_imports())
#        QObject.connect(extractMethodAction, SIGNAL("triggered()"), lambda: self._main._central.obtain_editor().extract_method())
        self.connect(moveUp, SIGNAL("triggered()"),
            actions.Actions()._editor_move_up)
        self.connect(moveDown, SIGNAL("triggered()"),
            actions.Actions()._editor_move_down)
        self.connect(duplicate, SIGNAL("triggered()"),
            actions.Actions()._editor_duplicate)
        self.connect(replaceTabsSpaces, SIGNAL("triggered()"),
            actions.Actions()._editor_replace_tabs_with_spaces)
        self.connect(removeTrailingSpaces, SIGNAL("triggered()"),
            actions.Actions()._editor_remove_trailing_spaces)
#        QObject.connect(showHideFindErrors, SIGNAL("triggered()"), self._show_hide_find_errors)

#    def _show_hide_find_errors(self):
#        editor = self._main._central.obtain_editor()
#        editor.findErrors = not editor.findErrors
#        editor._find_errors()
